var columns = [
    {
        field: 'index',
        title: '序号',
        align:"center",
        formatter:function(value, row, index){
            return index + 1;
        }
    },{
        field: 'parentId',
        align: 'center',
        title: '家长名称'
    },{
        field: 'orgId',
        align: 'center',
        title: '学生组织机构'
    },{
        field: 'subOrgId',
        align: 'center',
        title: '组织机构'
    },{
        field: 'name',
        align: 'center',
        title: '学生姓名'
    },{
        field: 'lessonAccount',
        align: 'center',
        title: '课时数'
    },{
        field: 'sex',
        title: '用户性别',
        align: 'center',
        formatter: function (value, row, index) {
            return pubForm.getSex(row.sex);
        }
    },{
        field: 'createTime',
        align: 'center',
        title: '创建时间'
    }
    // ,{
    //     field: 'state',
    //     title: '是否启用',
    //     align: 'center',
    //     formatter: function (value, row, index) {
    //         return pubSwitch.getSwitchBtnCss(row);
    //     }
    // },{
    //     field: 'operator',
    //     title: '操作',
    //     align: 'center',
    //     formatter: function (value, row, index) {
    //         console.log("aaaa");
    //         return pubOptBtn.getOptBtnCustom2('showUser',menuSub,row.orgId,row.parentId,row.id);
    //     }
    // }
    ];
var showUser={
    showUserInit:function () {
        sessionStorage.removeItem("orgId",orgId);
        sessionStorage.removeItem("orgName",orgName);
        if('0' == type){
            $("#topPurchaseNum").show();
        }
        if('1' == type && '3' == stype ){  //登录人总校长，点击菜单也是总校长
            $("#topPurchaseNum").show();
        }
        if('1' == type && '3' == stype ){  //登录人总校长，点击菜单也是分校长
            $("#topPurchaseNum").show();
        }
        $.ajax({
            url:application.contextPath+"/user/queryUserById",
            dataType:"json",
            type:"POST",
            data:{
                "userId":userId
            },
            success:function (res) {
                var data=res.data;
                $("#ObjId").val(userId);
                $("#loginName").val(data.loginName);
                $("#trueName").val(data.trueName);
                data.sex =="1" ? $("input[type='radio'][name='sex']").eq(0).attr("checked",true) : $("input[type='radio'][name='sex']").eq(1).attr("checked",true);
                $("#qqCode").val(data.qqCode);
                $("#qqName").val(data.qqName);
                $("#wechatCode").val(data.wechatCode);
                $("#wechatName").val(data.wechatName);
                $("#tel").val(data.tel);
                $("#email").val(data.email);
                $("#photo").val(data.photo);
                $("#orgName").val(data.orgName);
                $("#cityName").find("option[value='"+data.cityName+"']").attr("selected",true);
                $("#duty").find("option[value='"+data.duty+"']").attr("selected",true);
                if(null != data.userOrgAccount && '' != data.userOrgAccount){
                    if("" != data.userOrgAccount.lessonAccount && null != data.userOrgAccount.lessonAccount){
                        $("#purchaseNum").val(data.userOrgAccount.lessonAccount);
                    }else {
                        $("#purchaseNum").val("0");
                    }
                }else {
                    $("#purchaseNum").val("0");
                }
            }
        });
        pubForm.getBootTableSwitch("#tableList","/user/queryUserSubById","/base/switch/updateState",userId,"t_user_sub");
    },
    showUpdateUserOrgAccountPage:function(id){
        loadUtil = new Load($);
        loadUtil.load({
            container:'#homeContent',
            url: application.contextPath+"/user/showUpdateUserOrgAccountPage?orgId="+id.split(",")[0]+"&parentId="+id.split(",")[1]+"&type="+type+"&userId="+userId
        });
    },
    showUserOrgAccountPage:function(id){
        loadUtil = new Load($);
        loadUtil.load({
            container:'#homeContent',
            url: application.contextPath+"/user/showUserOrgAccountPage?orgId="+id.split(",")[0]+"&parentId="+id.split(",")[1]
        });
    },
    delUserOrgAccount:function(id){
        pubForm.delRow(id.split(",")[2],"/user/delUserOrgAccount","/user/queryUserSubById","#tableList");
    },
    showUserDescInit:function () {
        $.ajax({
            url:application.contextPath+"/user/queryUserDescAllByUserId",
            dataType:"json",
            type:"GET",
            async:false,
            data:{
                "userId":userId
            },
            success:function (res) {
                $.each(res.data.userProUrlList,function(index,item) {
                    var actClass = "";
                    if (index == 0){
                        actClass = "active";
                    }
                    var olList = '<li data-target="#carousel-example-captions" data-slide-to="'+index+'" class="'+actClass+'"></li>';
                    var imgList = '<div class="item '+actClass+'">\n' +
                        '<img src="'+item+'" '+
                        '</div>';

                    $("#olBn").append(olList);
                    $("#listBox").append(imgList);
                });
                //$("#userProfile").val(res.data.userProfile);
                if(res.data.userProfile != null && res.data.userProfile != ''){
                    tinyMCE.activeEditor.setContent(res.data.userProfile)
                }
            }
        });
    }
};

$(document).ready(function(){
     showUser.showUserInit();
    tinymce.init({
        convert_urls: false,
        selector: '.tinymce',
        height: 300,
        plugins: [
            'advlist autolink lists link image charmap print preview anchor',
            'searchreplace visualblocks code fullscreen',
            'insertdatetime media table contextmenu paste code'
        ],
        toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
        init_instance_callback:showUser.showUserDescInit
    });
});